package mt.tratapedidos;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import mt.comm.ClientSideMessage.Type;
import mt.dummy.ClientCommDummy;
import mt.dummy.ClientSideMessageDummy;

public class TrataPedidosCliente extends Thread {
	private ClientCommDummy clientCommDummy;
	private ObjectInputStream clientSocketIn;
	private ObjectOutputStream clientSocketOut;
	private boolean stop;

	public TrataPedidosCliente(ClientCommDummy clientCommDummy,
			ObjectInputStream clienteSocketIn,
			ObjectOutputStream clienteSocketOut) {

		this.clientCommDummy=clientCommDummy;
		this.clientSocketIn=clienteSocketIn;
		this.clientSocketOut=clienteSocketOut;
	}
	
	public void run(){
		stop=true;
		while(stop){
			
			try {
				ClientSideMessageDummy msg = (ClientSideMessageDummy) clientSocketIn.readObject();
			
				
				
				if(msg.getType().equals(mt.comm.ClientSideMessage.Type.ORDER)){
					clientCommDummy.addMessagesToQueue(msg);
					
					
					
					
				}
				if(msg.getType().equals(Type.ERROR)){
					stop=false;
				}
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
			
			
		}
		
	}

}
